1.2 FCN Layers
In the Classroom, we discussed the different layers that constitute a fully convolutional network
(FCN). The following code will introduce you to the functions that you need to build your seman-
tic segmentation model.
1.2.1 Separable Convolutions
The Encoder for your FCN will essentially require separable convolution layers, due to their ad-
vantages as explained in the classroom. The 1x1 convolution layer in the FCN, however, is a
regular convolution. Implementations for both are provided below for your use. Each includes
batch normalization with the ReLU activation function applied to the layers.
In [622]: def separable_conv2d_batchnorm(input_layer, filters, strides=1):
output_layer = SeparableConv2DKeras(filters=filters,kernel_size=3, strides=strides,
padding='same', activation='relu')(input_layer)
output_layer = layers.BatchNormalization()(output_layer)
return output_layer
def conv2d_batchnorm(input_layer, filters, kernel_size=3, strides=1):
output_layer = layers.Conv2D(filters=filters, kernel_size=kernel_size, strides=strides,
padding='same', activation='relu')(input_layer)
output_layer = layers.BatchNormalization()(output_layer)
return output_layer
1.2.2 Bilinear Upsampling
The following helper function implements the bilinear upsampling layer. Upsampling by a factor
of 2 is generally recommended, but you can try out different factors as well. Upsampling is used
in the decoder block of the FCN.
In [623]: def bilinear_upsample(input_layer):
output_layer = BilinearUpSampling2D((2,2))(input_layer)
return output_layer
1.3 Build the Model
In the following cells, you will build an FCN to train a model to detect and locate the hero target
within an image. The steps are: - Create an encoder_block - Create a decoder_block - Build the
FCN consisting of encoder block(s), a 1x1 convolution, and decoder block(s). This step requires
experimentation with different numbers of layers and filter sizes to build your model.
1.3.1 Encoder Block
Create an encoder block that includes a separable convolution layer using the
separable_conv2d_batchnorm() function. The filters parameter defines the size or depth
of the output layer. For example, 32 or 64.
2